package com.ocm.tourism.core.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ocm.tourism.core.dao.AuditInfoDao;
import com.ocm.tourism.core.domain.AuditBusinessAdvs;
import com.ocm.tourism.core.domain.AuditInfo;
import com.ocm.tourism.webclient.service.WebClientManager;

@Service
public class AuditServiceImpl implements AuditService {

   @Autowired
   private AuditInfoDao auditInfoDao;

   @Transactional(readOnly=false, propagation=Propagation.REQUIRED)
   public void saveAudit(AuditInfo auditInfo) {
      this.auditInfoDao.save(auditInfo);
   }

   @Override
   public boolean hasExistedAudit(String auditKey) {
      boolean hasResult = auditInfoDao.hasExistedAudit(auditKey);
      return hasResult;
   }

   @Override
   @Transactional(readOnly=false, propagation=Propagation.REQUIRED)
   public void saveAuditBusinessAdvs(AuditBusinessAdvs auditBusinessAdvs) {
      AuditBusinessAdvs existed = this.auditInfoDao.find(auditBusinessAdvs.getForeignKey(), auditBusinessAdvs.getTransalationType());
      if (existed != null){
         auditBusinessAdvs = existed;
      }
      WebClientManager.instance().getNextIndex(auditBusinessAdvs, auditInfoDao);
   }

   @Override
   public long getNextIndex() {
      
      return 0;
   }
}
